<?php

namespace Home\Model;
use Think\Model\RelationModel;

class UserModel extends RelationModel {

    protected $tableName = 'user';
    protected $pk = 'Id';

    protected $_link = array(
        'role'=>array(
            'mapping_type'      =>  self::MANY_TO_MANY,
            'class_name'        =>  'Role',
            'mapping_name'      =>  'roles',
            'foreign_key'       =>  'rid',
            'relation_foreign_key'  =>  'uid',
            'relation_table'    =>  'role_user' //此处应显式定义中间表名称，且不能使用C函数读取表前缀
        ),
        

        'car' => array(
            'mapping_type'  => self::HAS_MANY,
            'class_name'    => 'Car',
            'foreign_key'   => 'Id',
            'mapping_name'  => 'cars'
        
        ),

    );
    
}